<!DOCTYPE html>
<html>
<head>
    <title>登录</title>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta http-equiv="Content-Language" content="ch-cn">
    <script type="text/javascript" src="../script/jquery.js"></script>
    <script type="text/javascript">
        $(function()
        {
            $('#login').click(function()
            {
                var $name_error = $('#name_error').html("");
                var $pwd_error = $('#pwd_error').html("");
                var username = $('#username').val().trim();
                var password = $('#password').val().trim();
                var check = true;
                if (username == "")
                {
                    $name_error.html("用户名不能为空");
                    check = false;
                }
                if (password == "")
                {
                    $pwd_error.html("密码不能为空");
                    check = false;
                }
                if (check)
                {
                    $.post(
                            "login.do",
                            {"username":username, "password":password},
                            function(data)
                            {
                                if (data == "0")
                                {
                                    window.location.href = "/shopcar/list.do";
                                }
                                else if (data == "1")
                                {
                                    $name_error.html("用户名不存在");
                                }
                                else if (data == "2")
                                {
                                    $pwd_error.html("密码不正确");
                                }
                            }
                    );
                }
            });
        });
    </script>
</head>

<body background="../images/3.jpg" style="font-size:20px;">
<form>
    <h1 align="center">水果超市</h1><br>
    <table align="center">
        <tr>
            <td>用户名:</td>
            <td><input name="username" id="username"></td>
        </tr>
        <tr>
            <td><br/></td>
            <td><span id="name_error" style="color: red"></span></td>
        </tr>
        <tr>
            <td>密&nbsp;&nbsp;&nbsp;码:</td>
            <td><input type="password" id="password"></td>
        </tr>
        <tr>
            <td><br/></td>
            <td><span id="pwd_error" style="color:red"></span></td>
        </tr>
    </table>
    <p align="center">
        <input type="button" value="登录" id="login"/>
        <input type="reset" value="重置"/>
    </p>
</form>
</body>
</html>